﻿using System.Collections.Generic;

namespace Circa.Tools {
    public class SafeDictionary<TKey, TValue>: Dictionary<TKey,TValue> {
        public new TValue this[ TKey key ] {
            get {
                TValue value = default(TValue);
                TryGetValue( key, out value );
                return value;
            }
            set {
                if ( ContainsKey( key ) ) {
                    base[ key ] = value;
                } else {
                    Add( key, value );
                }
            }
        }

    }

}
